const autoprefixer = require('autoprefixer')
const pxtorem = require('postcss-pxtorem')

// 请求配置
const FETCH_BASEURL = {
  dev: '//xxxxxx/xxx/',
  test: '//xxxxxx/xxx/',
  uat: '//xxxxxx/xxx/',
  prod: '//xxxxxx/xxx/'
}

module.exports = (data) => {
  return {
    productionSourceMap: false,
    devServer: {
      disableHostCheck: true,
      port: 80,
      overlay: {
        warnings: false,
        errors: false,
      },
    },
    filenameHashing: true,
    configureWebpack: config => {
      config.output.chunkFilename = 'js/[name].js?t=[hash]'
      config.output.filename = 'js/[name].js?t=[hash]'
    },
    chainWebpack: config => {
      config.plugin('define').tap(args => {
        args[0]['process.env'].FETCH_BASEURL = JSON.stringify(
          FETCH_BASEURL[process.env.BUILD_ENV]
        )
        return args
      })
    },
    pages: {
      index: {
        title: '易卡拉权益',
        entry: 'src/main.js'
      }
    },
    publicPath: './',
    css: {
      loaderOptions: {
        postcss: {
          plugins: [
            autoprefixer({
              browsers: ['Android >= 4.0', 'iOS >= 7']
            }),
            pxtorem({
              rootValue: 75,
              propList: ['*'],
              selectorBlackList: ['van']
            })
          ]
        }
      }
    }
  }
}
